package com.zzw.hj18;

import java.util.Scanner;

/**
 * @Project: hw_java
 * @Description: 识别有效的IP地址和掩码并进行分类统计
 * @Author: zzw
 */
public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        // 统计A、B、C、D、E、错误IP地址或错误掩码、私有IP的个数，之间以空格隔开。
        // 【0.*.*.*】和【127.*.*.*】
        int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, s = 0;

        while (in.hasNext()) { //  while 处理多个 case
            //获取ip地址，掩码用字符串数组ips和yms存储
            String str = in.nextLine();
            String[] strs = str.split("~");
            String[] ips = strs[0].split("\\.");
            String[] yms = strs[1].split("\\.");

            //过滤掉非法长度IP地址
            if (ips.length != 4) {
                f++;
            }
            //过滤掉0.*.*.*】和【127.*.*.*】的IP地址
            else if (!ips[0].equals("0") && !ips[0].equals("127")) {
                boolean bl = true; //表示合法IP地址

                //是否为合法IP地址
                for (int i = 0; i < 4; i++) {
                    int t = Integer.parseInt(ips[i]);
                    if (t < 0 || t > 255) {
                        f++;
                        bl = false;
                        break;
                    }
                }
                //是否为合法掩码
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < 4; i++) {
                    int ym = Integer.parseInt(yms[i]);
                    for (int j = 7; j >= 0; j--) {
                        if ((ym & (1 << j)) > 0) {
                            sb.append("1");
                        } else {
                            sb.append("0");
                        }
                    }
                }
                int count0 = 0;
                int count1 = 0;
                for (int i = 0; i < sb.length(); i++) {
                    if (sb.charAt(i) == '0') count0++;
                    if (sb.charAt(i) == '1') count1++;
                    if ((i != sb.length() - 1) && sb.charAt(i) < sb.charAt(i + 1)) {
                        f++;
                        bl = false;
                        break;
                    }
                }
                if (count0 == sb.length() || count1 == sb.length()) {
                    f++;
                    bl = false;
                }
                //合法IP地址属于哪一类
                if (bl) {
                    int t = Integer.parseInt(ips[0]);
                    int v = Integer.parseInt(ips[1]);
                    if (t <= 126 && t >= 1) {
                        a++;
                        if (t == 10) s++;
                    } else if (t <= 191 && t >= 127) {
                        b++;
                        if (t == 172 && v == 16) s++;
                    } else if (t <= 223 && t >= 192) {
                        c++;
                        if (t == 192 && v == 168) s++;
                    } else if (t <= 239 && t >= 224) {
                        d++;
                    } else if (t <= 255 && t >= 240) {
                        e++;
                    }
                }
            }

        }
        //输出
        System.out.print(a + " ");
        System.out.print(b + " ");
        System.out.print(c + " ");
        System.out.print(d + " ");
        System.out.print(e + " ");
        System.out.print(f + " ");
        System.out.print(s);
    }
}